package question4;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class BetterForDemo {
    public static void main(String[] args) {
        //Collection<Double> list = new ArrayList<>(List.of(88.5,39.2,77.1,5.6,8.8,9.9,59.5,9.9));
        //System.out.println("list = " + list);
      List<? extends Number> list = List.of(88.5, 39.2, 77.1, 56.8, 89, 99, 59.5);
        for (Number number: list) {
            System.out.print(number+"  ");
        }
        System.out.println("\r");
        for (Number number : list) {
           //(number.doubleValue()<60)?System.out.println(number):continue;
            if (number.doubleValue()<60){
                System.out.print(number+"  ");
            }
        }
        int count=0;
        double sum=0;
        for (Number number : list) {
            //(number.doubleValue()<60)?System.out.println(number):continue;
            if (number.doubleValue()<60){
                count++;
                sum+=number.doubleValue();
            }
        }
        BigDecimal bigsum = new BigDecimal(sum);
        BigDecimal bigcount = new BigDecimal(count);
        double average=bigsum.divide(bigcount,2, RoundingMode.HALF_UP).doubleValue();
        System.out.println("不及格人数为："+count+"平均分数为："+average);
        double max=0;
        for (Number number : list) {
            if (number.doubleValue()>max){
                max=number.doubleValue();
            }
        }
        System.out.println("最大分数为："+max);
    }
}


//Double   ----  Number ?
//class Double extends Number {...}

//public ArrayList(Collection<? extends E> c) {
//下限限定。  只能是 E的儿子们。
//---》 List.of(88.5,39.2,77.1,56.8,89,99,59.5)  ---》 Double 类型
//
